package com.betty.cscams.service.impl;

import java.util.Date;
import java.util.List;

import com.betty.cscams.common.page.MybatisPageHelper;
import com.betty.cscams.common.page.PageRequest;
import com.betty.cscams.common.page.PageResult;
import com.betty.cscams.constant.SysConstants;
import com.betty.cscams.entity.BusTerm;
import com.betty.cscams.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.betty.cscams.dao.BusTermMapper;
import com.betty.cscams.service.BusTermService;

/**
 * ---------------------------
 *  (BusTermServiceImpl)         
 * ---------------------------
 * 时间：  2022-03-12 09:20:50
 * ---------------------------
 */
@Service
public class BusTermServiceImpl implements BusTermService {

	@Autowired
	private BusTermMapper busTermMapper;

	@Override
	public int save(BusTerm record) {
		record.setLastUpdateBy(SecurityUtils.getUsername());
		record.setLastUpdateTime(new Date());
		if(record.getId() == null || record.getId() == 0) {
			record.setCreateBy(SecurityUtils.getUsername());
			record.setCreateTime(new Date());
			record.setStatus(SysConstants.TERM_STATUS_1);
			return busTermMapper.add(record);
		}
		return busTermMapper.update(record);
	}

	@Override
	public int delete(BusTerm record) {
		return busTermMapper.delete(record.getId());
	}

	@Override
	public int delete(List<BusTerm> records) {
		for(BusTerm record:records) {
			delete(record);
		}
		return 1;
	}

	@Override
	public BusTerm findById(Long id) {
		return busTermMapper.findById(id);
	}

	@Override
	public PageResult findPage(PageRequest pageRequest) {
		Object label = pageRequest.getParam("label");
		return MybatisPageHelper.findPage(pageRequest, busTermMapper,"findPage",label);
	}

	@Override
	public int updateStatus(BusTerm busTerm) {

		return busTermMapper.update(busTerm);
	}

	@Override
	public List<BusTerm> findOptions(int type) {
		return busTermMapper.findOptions(type);
	}

	@Override
	public BusTerm findCurrentTerm() {
		return busTermMapper.findCurrentTerm();
	}

}
